package com.ruike.alisurface.Serials;

import android.text.TextUtils;

import com.voodoo.lib_utils.ShareUtils;

import java.util.HashMap;

public class SavesimInfo {

    /**
     * @Params: 一个串口数据回调接口
     */
    public interface SavesimInfoCallBack {
        void onSerialPortData(String serialPortData, byte[] resultBytes);
    }

    public static void setSavesimInfoCallBack(SavesimInfoCallBack serial3CallBack) {
        mSavesimInfoCallBack = serial3CallBack;
    }

    public static SavesimInfoCallBack mSavesimInfoCallBack;

    /**
     * @Params: 一个串口数据解析回调接口
     */
    public interface SendInfoCallBack {
        void onMsg(int sendType, String serialPortData);
    }

    public static void setSendInfoCallBack(SendInfoCallBack sendInfoCallBack) {
        mSendInfoCallBack = sendInfoCallBack;
    }

    public static SendInfoCallBack mSendInfoCallBack;

    public final static String MV = "MV";
    public final static String Fir = "Fir";

    public final static String Sec = "Sec";

    public final static String Thi = "Thi";
    public final static String Fou = "Fou";
    public final static String MCPU = "MCPU";
    public final static String TMPEDP = "TMPEDP";
    public final static String ELCTRICIRY = "ELCTRICIRY";


    public final static String T0 = "T0";
    public final static String T1 = "T1";
    public final static String T2 = "T2";
    public final static String T3 = "T3";
    public final static String T4 = "T4";

    public final static String T0C = "T0C";
    public final static String T1C = "T1C";
    public final static String T2C = "T2C";
    public final static String T3C = "T3C";
    public final static String T4C = "T4C";


    public final static String temhum = "temhum";
    public final static String temhum1 = "temhum1";
    public final static String temhum2 = "temhum2";
    public final static String temhum3 = "temhum3";
    public final static String temhum4 = "temhum4";


    /**
     * 板子 版本信息
     *
     * @return
     */
    public static HashMap<String, String> BzVersion(int type) {
        HashMap<String, String> map = new HashMap<>();
        map.put(MV, ShareUtils.getInstance().getString(MV, ""));
        map.put(Fir, ShareUtils.getInstance().getString(Fir, ""));
        map.put(Sec, ShareUtils.getInstance().getString(Sec, ""));
        map.put(Thi, ShareUtils.getInstance().getString(Thi, ""));
        map.put(Fou, ShareUtils.getInstance().getString(Fou, ""));
        if (type == 1) {
            map.put(MCPU, ShareUtils.getInstance().getString(MCPU, ""));
            map.put(TMPEDP, ShareUtils.getInstance().getString(TMPEDP, ""));
        } else {
            map.put(MCPU, MCPU());
            map.put(TMPEDP, TMPEDP());
        }

        return map;
    }

    public static void main(String[] args) {
        MCPU();
    }

    public static String MCPU() {
        String str = ShareUtils.getInstance().getString(MCPU, "");
        StringBuilder version_pc = new StringBuilder();
        if (!TextUtils.isEmpty(str)) {
            String[] data = str.split("\\|");
            String[] data_code = {"02", "03", "04", "05", "06"};
            for (int i = 0; i < data.length; i++) {
                version_pc.append(data_code[i]).append(data[i]);
                if (i != data.length - 1) {
                    version_pc.append("|");
                }
            }
        }
        return version_pc.toString();
    }

    public static String TMPEDP() {
        String str = ShareUtils.getInstance().getString(TMPEDP, "");
        StringBuilder version_pc = new StringBuilder();
        if (!TextUtils.isEmpty(str)) {
            String[] data = str.split("\\|");
            //柜子编号
            String[] data_cabinet = {"02", "03", "04", "05", "06"};
            for (int i = 0; i < data.length; i++) {
                version_pc.append(data_cabinet[i]).append(data[i]);
                if (i != data.length - 1) {
                    version_pc.append("|");
                }
            }
        }
        return version_pc.toString();
    }

    public static String ELCTRICIRY() {
        String str = ShareUtils.getInstance().getString(ELCTRICIRY, "");
        StringBuilder version_pc = new StringBuilder();
        if (!TextUtils.isEmpty(str)) {
            String[] data = str.split("\\|");
            //柜子编号
            String[] data_cabinet = {"02", "03", "04", "05", "06"};
            for (int i = 0; i < data.length; i++) {
                version_pc.append(data_cabinet[i]).append(data[i]);
                if (i != data.length - 1) {
                    version_pc.append("|");
                }
            }
        }
        return version_pc.toString();
    }

    /**
     * 温控板子 版本信息
     *
     * @return
     */
    public static HashMap<String, String> WkVersion() {

        HashMap<String, String> map = new HashMap<>();
        String mTO = ShareUtils.getInstance().getString(T0, "");
        if (!TextUtils.isEmpty(mTO)) {
            map.put(T0, mTO);
        }

        String mT1 = ShareUtils.getInstance().getString(T1, "");
        if (!TextUtils.isEmpty(mT1)) {
            map.put(T1, mT1);
        }

        String mT2 = ShareUtils.getInstance().getString(T2, "");
        if (!TextUtils.isEmpty(mT2)) {
            map.put(T2, mT2);
        }

        String mT3 = ShareUtils.getInstance().getString(T3, "");
        if (!TextUtils.isEmpty(mT3)) {
            map.put(T3, mT3);
        }

        String mT4 = ShareUtils.getInstance().getString(T4, "");
        if (!TextUtils.isEmpty(mT4)) {
            map.put(T4, mT4);
        }
        String mTOC = ShareUtils.getInstance().getString(T0C, "");
        if (!TextUtils.isEmpty(mTOC)) {
            map.put(T0C, mTOC);
        }
        String mT1C = ShareUtils.getInstance().getString(T1C, "");
        if (!TextUtils.isEmpty(mT1C)) {
            map.put(T1C, mT1C);
        }
        String mT2C = ShareUtils.getInstance().getString(T2C, "");
        if (!TextUtils.isEmpty(mT2C)) {
            map.put(T2C, mT2C);
        }
        String mT3C = ShareUtils.getInstance().getString(T3C, "");
        if (!TextUtils.isEmpty(mT3C)) {
            map.put(T3C, mT3C);
        }
        String mT4C = ShareUtils.getInstance().getString(T4C, "");
        if (!TextUtils.isEmpty(mT4C)) {
            map.put(T4C, mT4C);
        }
        return map;
    }


    /**
     * 温控板子心跳
     *
     * @return
     */
    public static HashMap<String, String> WkHeart() {
        HashMap<String, String> map = new HashMap<>();
        map.put(temhum, ShareUtils.getInstance().getString(temhum, ""));
        map.put(temhum1, ShareUtils.getInstance().getString(temhum1, ""));
        map.put(temhum2, ShareUtils.getInstance().getString(temhum2, ""));
        map.put(temhum3, ShareUtils.getInstance().getString(temhum3, ""));
        map.put(temhum4, ShareUtils.getInstance().getString(temhum4, ""));
        return map;
    }

    /**
     * 重置温控和驱动板子 版本信息
     *
     * @return
     */
    public static void clearBzVersionInfo() {
        ShareUtils.getInstance().putString(MV, "");

        ShareUtils.getInstance().putString(T0, "");
        ShareUtils.getInstance().putString(T1, "");
        ShareUtils.getInstance().putString(T2, "");
        ShareUtils.getInstance().putString(T3, "");
        ShareUtils.getInstance().putString(T4, "");

        ShareUtils.getInstance().putString(Fir, "");
        ShareUtils.getInstance().putString(Sec, "");
        ShareUtils.getInstance().putString(Thi, "");
        ShareUtils.getInstance().putString(Fou, "");

        ShareUtils.getInstance().putString(MCPU, "");
        ShareUtils.getInstance().putString(TMPEDP, "");
    }
}
